package model;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import javax.servlet.http.HttpSession;

public class MiniCart {
	private Map<Integer, Integer> quantities = new HashMap<Integer, Integer>();
	public void addItem(String inventoryId, String count){
		if(inventoryId == null){
			throw new IllegalArgumentException("Inventory id can not be null!");
		}
		int inventoryIdInt = Integer.parseInt(inventoryId);
		int quantityInt = 1;
		if(count!=null){
			quantityInt = Integer.parseInt(count);
		}
		quantities.put(inventoryIdInt, quantityInt);
		
	}
	public Map<Integer, Integer> getQuantities(){
		return this.quantities;
	}
	
	public Set<Integer> getInventoryIds(){
		return this.quantities.keySet();
	}
	
	public static MiniCart get(HttpSession session){
		MiniCart miniCart = (MiniCart) (session.getAttribute("miniCart"));
		if (miniCart == null){
			miniCart = new MiniCart();
		}
		return miniCart;
	}
}
